/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modulos.recordatorio.vista;

import basedatos.OperacionesBD;
import java.io.File;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import modulos.recordatorio.modelo.Recordatorio;
import modulos.usuario.modelo.Permiso;
import modulos.usuario.modelo.Usuario;
import vista.frmPrincipal;
import vista.sonidos.Audio;

/**
 *
 * @author francisco
 */
public class DialogoRecordatorio extends javax.swing.JDialog {

    Audio reproduce;
    public String dirAlarma;
    Recordatorio rec;

    /**
     * Creates new form DialogoRecordatorio
     */
    public DialogoRecordatorio(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        direcAlarma();
    }

    private void direcAlarma() {
        dirAlarma =getClass().getResource("/vista/sonidos/Hip-hop_Alarm.mp3").getPath();
//        String system = System.getProperty("os.name");
//        if (system.startsWith("Linux")) {
//            dirAlarma = System.getProperty("user.dir") + "/alarmas/Hip-hop_Alarm.mp3";
//        } else if (system.startsWith("Windows")) {
//            dirAlarma = System.getProperty("user.dir") + "\\alarmas\\Hip-hop_Alarm.mp3";
//        }
    }
//Otro constructor

    public DialogoRecordatorio(java.awt.Frame parent, boolean modal, Recordatorio r) {
        super(parent, modal);
        initComponents();
        direcAlarma();
        rec = r;
        lblTitulo.setText(rec.getTitulo());
        textoDescripcion.setText(rec.getDetalle());
        try {
            Usuario usuario = (Usuario) frmPrincipal.UsuarioLogueado.get(0)[1];
            Permiso permiso = (Permiso) OperacionesBD.buscar("Permiso", "usuario_idPersona", usuario.getIdPersona() + "");

            if (permiso != null) {
                if (permiso.getDirAlarma() != null) {
                    dirAlarma = permiso.getDirAlarma();
                }
            }
            reproducir();
        } catch (URISyntaxException ex) {
            Logger.getLogger(DialogoRecordatorio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void reproducir() throws URISyntaxException {
        reproduce = new Audio();
        File archivo = new File(dirAlarma);
        reproduce.reproducir(archivo);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        lblTitulo = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        textoDescripcion = new javax.swing.JTextArea();
        btnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(null);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/xclock.png"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(50, 100, 32, 50);

        lblTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        getContentPane().add(lblTitulo);
        lblTitulo.setBounds(30, 10, 360, 30);

        textoDescripcion.setBackground(new java.awt.Color(227, 220, 220));
        textoDescripcion.setColumns(20);
        textoDescripcion.setLineWrap(true);
        textoDescripcion.setRows(5);
        jScrollPane2.setViewportView(textoDescripcion);

        getContentPane().add(jScrollPane2);
        jScrollPane2.setBounds(100, 60, 290, 140);

        btnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/accept.png"))); // NOI18N
        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAceptar);
        btnAceptar.setBounds(170, 210, 100, 30);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-410)/2, (screenSize.height-286)/2, 410, 286);
    }// </editor-fold>//GEN-END:initComponents

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        reproduce.parar();
        dispose();
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        reproduce.parar();
    }//GEN-LAST:event_formWindowClosing
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JTextArea textoDescripcion;
    // End of variables declaration//GEN-END:variables

}
